home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-11 | 4.3 KB | 196 lines | [TEXT/SPM ] |
- //• SpriteHelp.c by Stefan C. Sinclair Copyright © 1996 All Rights Reserved
-
- #include "SpriteHelp.h"
-
- /**************/
- /* Globals */
- /**************/
-
- extern CWindowPtr gWindowP;
-
- ControlActionUPP gActionUPP;
- Rect pictRect, windRect;
- PicHandle helpPict;
- Boolean helpDone;
- short numScreens;
-
- void Helper(short whichOne)
- {
- short pictWide, pictHigh, windWide, windHigh;
- Rect oldWindRect;
-
- helpPict = GetPicture(whichOne);
- if(helpPict == nil)
- CantFindResource();
-
- HLock((Handle)helpPict);
- pictRect = (**helpPict).picFrame;
- HUnlock((Handle)helpPict);
-
- pictWide = pictRect.right - pictRect.left;
- pictHigh = pictRect.bottom - pictRect.top;
-
- oldWindRect = gWindowP->portRect;
-
- windRect = oldWindRect;
- windRect.right = windRect.left + kScrollBarWidth + pictWide;
- windWide = windRect.right - windRect.left;
- windHigh = windRect.bottom - windRect.top;
-
- /*pictRect.top = windRect.top;
- pictRect.left = windRect.left;
- pictRect.bottom = pictRect.top + pictHigh;
- pictRect.right = pictRect.left + pictWide; */
-
- numScreens = 4*pictHigh/(windRect.bottom - windRect.top);
- gActionUPP = NewControlActionProc( ScrollProc );
-
- SizeWindow((WindowPtr)gWindowP, windWide, windHigh, FALSE);
- SetUpScrollBar((WindowPtr)gWindowP);
- InvalRect(&gWindowP->portRect);
-
- // Event loop
- FlushEvents(everyEvent, 0);
- HelpEventLoop();
- FlushEvents(everyEvent, 0);
-
- // All done
- ReleaseResource((Handle)helpPict);
- KillControls((WindowPtr)gWindowP);
- windWide = oldWindRect.right - oldWindRect.left;
- windHigh = oldWindRect.bottom - oldWindRect.top;
- SizeWindow((WindowPtr)gWindowP, windWide, windHigh, FALSE);
- InvalRect(&gWindowP->portRect);
- }
-
- void SetUpScrollBar( WindowPtr window )
- {
- Rect vScrollRect;
- ControlHandle scrollBarH;
-
- vScrollRect = window->portRect;
- vScrollRect.left = vScrollRect.right - kScrollBarWidth;
-
- scrollBarH = NewControl( window, &vScrollRect,
- kEmptyTitle, kVisible, kStartValue, kMinValue,
- numScreens+1, scrollBarProc, kNilRefCon );
- }
-
- pascal void ScrollProc( ControlHandle theControl, short partCode )
- {
- short curCtlValue, maxCtlValue, minCtlValue, scrollAmt;
- WindowPtr window;
-
- scrollAmt = (pictRect.bottom - pictRect.top)/(numScreens+1);
-
- maxCtlValue = GetCtlMax( theControl );
- curCtlValue = GetCtlValue( theControl );
- minCtlValue = GetCtlMin( theControl );
-
- window = (**theControl).contrlOwner;
-
- switch ( partCode )
- {
- case inPageDown:
- case inDownButton:
- if ( curCtlValue < maxCtlValue )
- {
- curCtlValue += 1;
- SetCtlValue( theControl, curCtlValue );
- pictRect.top-=scrollAmt;
- pictRect.bottom-=scrollAmt;
- InvalRect(&window->portRect);
- }
- break;
- case inPageUp:
- case inUpButton:
- if ( curCtlValue > minCtlValue )
- {
- curCtlValue -= 1;
- SetCtlValue( theControl, curCtlValue );
- pictRect.top+=scrollAmt;
- pictRect.bottom+=scrollAmt;
- InvalRect(&window->portRect);
- }
- break;
- }
- }
-
- void HelpEventLoop( void )
- {
- EventRecord event;
-
- helpDone = false;
-
- while ( helpDone == false )
- {
- if ( WaitNextEvent( everyEvent, &event, kSleep, nil ) )
- HelpDoEvent( &event );
- }
- }
-
- void HelpDoEvent( EventRecord *eventPtr )
- {
- WindowPtr window;
- Rect viewRect;
-
- switch ( eventPtr->what )
- {
- case mouseDown:
- HelpHandleMouseDown( eventPtr );
- break;
- case updateEvt:
- window = (WindowPtr)eventPtr->message;
- viewRect = window->portRect;
- viewRect.right -= kScrollBarWidth;
- BeginUpdate( window );
- EraseRect(&viewRect);
- HLock((Handle)helpPict);
- DrawPicture(helpPict, &pictRect );
- HUnlock((Handle)helpPict);
- DrawControls( window );
- EndUpdate( window );
- break;
- }
- }
-
- void HelpHandleMouseDown( EventRecord *eventPtr )
- {
- WindowPtr window;
- short thePart;
- Point thePoint;
- ControlHandle theControl;
-
- thePart = FindWindow( eventPtr->where, &window );
- switch ( thePart )
- {
- case inSysWindow :
- //SystemClick( eventPtr, window );
- break;
- case inDrag :
- DragWindow( window, eventPtr->where, &qd.screenBits.bounds );
- break;
- case inContent:
- thePoint = eventPtr->where;
- GlobalToLocal( &thePoint );
-
- thePart = FindControl(thePoint, window, &theControl);
-
- if ( theControl == ((WindowPeek)window)->controlList )
- {
- if ( thePart == inThumb )
- {
- return;
- }
- else
- {
- thePart = TrackControl( theControl, thePoint, gActionUPP );
- }
- }
- break;
- case inGoAway:
- if(TrackGoAway(window, eventPtr->where))
- helpDone = TRUE;
- break;
- }
- }